//
//  FileManagerViewController.m
//  iOS UI Sample Code
//
//  Created by 규성 이 on 12. 7. 9..
//  Copyright (c) 2012년 kkamci77@gmail.com. All rights reserved.
//

#import "FileManagerViewController.h"

@interface FileManagerViewController ()

@end

@implementation FileManagerViewController
@synthesize lblFirst, lblSecond, lblThird, lblFourth;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSFileManager * fileMng = [NSFileManager defaultManager];
    
    [self.lblFirst setText:[fileMng currentDirectoryPath]];
    
    [self.lblSecond setText:NSHomeDirectory()];
    
    NSArray * dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * docsDir;
    docsDir = [dirPaths objectAtIndex:0];
    [self.lblThird setText:docsDir];
    
    [self.lblFourth setText:NSTemporaryDirectory()];
    NSLog(@"Use Direct Macro");
    NSLog(@"Temporary Directory = %@", NSTemporaryDirectory());
    NSLog(@"Home Directory = %@", NSHomeDirectory());
    NSLog(@"Use NSSearchPathForDirectorysInDomains");
    NSLog(@"Documents Directory = %@", NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES));
    NSLog(@"Cache Directory = %@", NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES));
    
    
//    NSDirectoryEnumerator *dirEnum = [fileMng enumeratorAtPath:NSHomeDirectory()];
//    NSString * file;
//    
//    while(file = [dirEnum nextObject])
//    {
//        NSLog(@"Directorys = %@", file);
//    }
    
    
}


- (void)changeDirectory
{
    NSFileManager * fileManager;
    NSArray * dirPaths;
    NSString * docsPath;
    
    
    fileManager = [NSFileManager defaultManager];
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsPath = [dirPaths objectAtIndex:0];
    if([fileManager changeCurrentDirectoryPath:docsPath] == NO)
    {
        NSLog(@"Don't exist directory");
    }
    
    // do action.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc
{
    [lblFirst release];
    [lblSecond release];
    [lblThird release];
    [lblFourth release];
    [super dealloc];
}

@end
